package fr.inserm.u915.tabixserver;

public class Segment
	implements Comparable<Segment>
	{
	private String chromosome;
	private int start;
	private int end;
	
	
	
	public Segment(String chromosome, int start, int end)
		{
		this.chromosome = chromosome;
		this.start = start;
		this.end = end;
		}
	
	
	
	public String getChromosome() {
		return chromosome;
		}
	public int getStart() {
		return start;
		}
	public int getEnd() {
		return end;
		}
	@Override
	public int hashCode()
		{
		final int prime = 31;
		int result = 1;
		result = prime * result + chromosome.hashCode();
		result = prime * result + end;
		result = prime * result + start;
		return result;
		}
	
	@Override
	public int compareTo(Segment o)
		{
		int i=getChromosome().compareTo(o.getChromosome());
		if(i!=0) return i;
		i=getStart()-o.getStart();
		if(i!=0) return i;
		return getEnd()-o.getEnd();
		}
	
	@Override
	public boolean equals(Object obj)
		{
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		Segment other = (Segment) obj;
		if (end != other.end)
			return false;
		if (start != other.start)
			return false;
		if (!chromosome.equals(other.chromosome))
			return false;
		return true;
		}
	public  Segment cast(ChromNameNormalizer naming)
		{
		String s=naming.normalize(chromosome);
		if(s==chromosome) return this;
		return new Segment(s, start, end);
		}
	@Override
	public String toString() {
		return chromosome+":"+start+"-"+end;
		}
	}
